package com.zhitan.netty.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 云快充（自定义）命令枚举
 */
@Getter
@AllArgsConstructor
public enum FrameTypeEnum {

    // 未知帧
    UNKNOWN((byte) 0x00, "UNKNOWN", "未知帧类型", (byte) 0x00, "UNKNOWN"),

    // 起始帧
    START((byte) 0x68, "START", "起始帧", (byte) 0x00, "UNKNOWN"),
    LOGIN((byte) 0x01, "LOGIN", "充电桩登录认证", (byte) 0x0C, "STATUS"),
    LOGIN_RES((byte) 0x02, "LOGIN_RES", "登录认证应答", (byte) 0x00, "CMD"),
    HEART_BEAT((byte) 0x03, "HEART_BEAT", "充电桩心跳包", (byte) 0x0D, "STATUS"),
    HEART_BEAT_RES((byte) 0x04, "HEART_BEAT_RES", "心跳包应答", (byte) 0x00, "CMD"),
    FEE_MODEL_CHECK_REQ((byte) 0x05, "FEE_MODEL_CHECK_REQ", "计费模型验证请求", (byte) 0x0E, "CMD"),
    FEE_MODEL_CHECK_RES((byte) 0x06, "FEE_MODEL_CHECK_RES", "计费模型验证请求应答", (byte) 0x00, "CMD"),
    FEE_MODEL_REQ((byte) 0x09, "FEE_MODEL_REQ", "充电桩计费模型请求", (byte) 0x5E, "CMD"),
    FEE_MODEL_RES((byte) 0x0A, "FEE_MODEL_RES", "计费模型请求应答", (byte) 0x0B, "CMD"),
    READ_REAL_TIME_DATA((byte) 0x12, "READ_REAL_TIME_DATA", "读取实时监测数据", (byte) 0x0C, "CMD"),
    UPLOAD_OFFLINE_DATA((byte) 0x13, "UPLOAD_OFFLINE_DATA", "实时监测数据", (byte) 0x00, "STATUS"),
    CHARGING_HANDSHAKE((byte) 0x15, "CHARGING_HANDSHAKE", "充电握手", (byte) 0x00, "STATUS"),
    PARAM_SET((byte) 0x17, "PARAM_SET", "参数配置", (byte) 0x00, "STATUS"),
    CHARGING_END((byte) 0x19, "CHARGING_END", "充电结束", (byte) 0x00, "STATUS"),
    ERROR_FRAME_DATA((byte) 0x1B, "ERROR_FRAME_DATA", "错误报文", (byte) 0x00, "STATUS"),
    BMS_STOP((byte) 0x1D, "BMS_STOP", "充电阶段BMS中止", (byte) 0x00, "STATUS"),
    BATTERY_CHARGER_STOP((byte) 0x21, "BATTERY_CHARGER_STOP", "充电阶段充电机中止", (byte) 0x00, "STATUS"),
    BMS_OUTPUT_DATA((byte) 0x23, "BMS_OUTPUT_DATA", "充电过程BMS需求、充电机输出", (byte) 0x00, "STATUS"),
    BMS_INFO((byte) 0x25, "BMS_INFO", "充电过程BMS信息", (byte) 0x00, "STATUS"),
    PILE_START_CHARGING((byte) 0x31, "PILE_START_CHARGING", "充电桩主动申请启动充电（刷卡充电）", (byte) 0x2A, "STATUS"),
    PILE_START_CHARGING_RES((byte) 0x32, "PILE_START_CHARGING_RES", "运营平台确认启动充电", (byte) 0x00, "CMD"),
    START_CHARGING_RES((byte) 0x33, "START_CHARGING_RES", "远程启机命令回复", (byte) 0x00, "STATUS"),
    START_CHARGING_REQ((byte) 0x34, "START_CHARGING_REQ", "运营平台远程控制启机", (byte) 0x30, "CMD"),
    STOP_CHARGING_RES((byte) 0x35, "STOP_CHARGING_RES", "远程停机命令回复", (byte) 0x00, "STATUS"),
    STOP_CHARGING_REQ((byte) 0x36, "STOP_CHARGING_REQ", "运营平台远程停机", (byte) 0x0C, "CMD"),
    SETTLEMENT_BILL((byte) 0x3B, "SETTLEMENT_BILL", "交易记录", (byte) 0x15, "STATUS"),
    SETTLEMENT_BILL_CONFIRM((byte) 0x40, "SETTLEMENT_BILL_CONFIRM", "交易记录确认", (byte) 0x00, "CMD"),
    UPDATE_BALANCE_RES((byte) 0x41, "UPDATE_BALANCE_RES", "余额更新应答", (byte) 0x00, "STATUS"),
    UPDATE_REMOTE_BALANCE_REQ((byte) 0x42, "UPDATE_REMOTE_BALANCE_REQ", "远程账户余额更新", (byte) 0x17, "CMD"),
    SYNC_CARD_RES((byte) 0x43, "SYNC_CARD_RES", "卡数据同步应答", (byte) 0x00, "STATUS"),
    SYNC_CARD((byte) 0x44, "SYNC_CARD", "离线卡数据同步", (byte) 0x00, "CMD"),
    CLEAR_CARD_RES((byte) 0x45, "CLEAR_CARD_RES", "离线卡数据清除应答", (byte) 0x00, "STATUS"),
    CLEAR_CARD_REQ((byte) 0x46, "CLEAR_CARD_REQ", "离线卡数据清除", (byte) 0x00, "CMD"),
    GET_OFFLINE_CARD_DATA_RES((byte) 0x47, "GET_OFFLINE_CARD_DATA_RES", "离线卡数据查询应答", (byte) 0x00, "STATUS"),
    GET_OFFLINE_CARD_DATA_REQ((byte) 0x48, "GET_OFFLINE_CARD_DATA_REQ", "离线卡数据查询", (byte) 0x00, "CMD"),
    SET_WORK_SETTING_RES((byte) 0x51, "SET_WORK_SETTING_RES", "充电桩工作参数设置应答", (byte) 0x00, "STATUS"),
    SET_WORK_SETTING_REQ((byte) 0x52, "SET_WORK_SETTING_REQ", "充电桩工作参数设置", (byte) 0x11, "CMD"),
    TIME_SET_RES((byte) 0x55, "TIME_SET_RES", "对时设置应答", (byte) 0x00, "STATUS"),
    TIME_SET_REQ((byte) 0x56, "TIME_SET_REQ", "对时设置", (byte) 0x12, "CMD"),
    FEE_MODEL_SET_RES((byte) 0x57, "FEE_MODEL_SET_RES", "计费模型应答", (byte) 0x00, "STATUS"),
    FEE_MODEL_SET_REQ((byte) 0x58, "FEE_MODEL_SET_REQ", "计费模型设置", (byte) 0x5E, "CMD"),
    GROUND_LOCK_REQ((byte) 0x61, "GROUND_LOCK_REQ", "地锁数据上送（充电桩上送）", (byte) 0x00, "STATUS"),
    GROUND_LOCK_RES((byte) 0x62, "GROUND_LOCK_RES", "遥控地锁升锁与降锁命令（下行）", (byte) 0x00, "CMD"),
    PILE_RETURN_DATA((byte) 0x63, "PILE_RETURN_DATA", "充电桩返回数据（上行）", (byte) 0x00, "STATUS"),
    OFFLINE_ORDER_START_REQ((byte) 0x70, "OFFLINE_ORDER_START_REQ", "离线检测数据启动传输", (byte) 0x1D, "STATUS"),
    OFFLINE_ORDER_START_RES((byte) 0x71, "OFFLINE_ORDER_START_RES", "离线检测数据启动传输应答", (byte) 0x00, "CMD"),
    OFFLINE_ORDER_DATA_REQ((byte) 0x72, "OFFLINE_ORDER_DATA_REQ", "离线监测数据上传", (byte) 0x1D, "STATUS"),
    OFFLINE_ORDER_DATA_RES((byte) 0x73, "OFFLINE_ORDER_DATA_RES", "离线监测数据上传确认", (byte) 0x00, "CMD"),
    OFFLINE_ORDER_SETTLEMENT_BILL_REQ((byte) 0x74, "OFFLINE_ORDER_SETTLEMENT_BILL_REQ", "离线交易记录", (byte) 0x15, "STATUS"),
    OFFLINE_ORDER_SETTLEMENT_BILL_RES((byte) 0x75, "OFFLINE_ORDER_SETTLEMENT_BILL_RES", "离线交易记录确认", (byte) 0x00, "CMD"),
    READ_SIM_CARD_INFO((byte) 0x76, "READ_SIM_CARD_INFO", "读取SIM卡", (byte) 0x0B, "CMD"),
    READ_SIM_CARD_INFO_RES((byte) 0x77, "READ_SIM_CARD_INFO_RES", "读取SIM卡回复", (byte) 0x00, "STATUS"),
    REBOOT_RES((byte) 0x91, "REBOOT_RES", "远程重启应答", (byte) 0x00, "STATUS"),
    REBOOT_REQ((byte) 0x92, "REBOOT_REQ", "远程重启", (byte) 0x0C, "CMD"),
    OTA_RES((byte) 0x93, "OTA_RES", "远程更新应答", (byte) 0x00, "STATUS"),
    OTA_REQ((byte) 0x94, "OTA_REQ", "远程更新", (byte) 0x62, "CMD"),
    QR_CODE_REQ((byte) 0xF0, "QR_CODE_REQ", "下发二维码", (byte) 0x62, "CMD");

    /**
     * 帧码
     */
    private final byte code;
    /**
     * 帧名称
     */
    private final String name;
    /**
     * 帧描述
     */
    private final String desc;
    /**
     * 回复数据长度
     */
    private final byte resLen;
    /**
     * 帧类型
     */
    private final String frameType;

    /**
     * 根据code获取枚举
     */
    public static FrameTypeEnum getByCode(byte code) {
        for (FrameTypeEnum value : FrameTypeEnum.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return UNKNOWN;
    }
}
